package cn.zl.springbootredis.redis;

import cn.zl.springbootredis.SpringbootRedisApplication;
import cn.zl.springbootredis.entity.User;
import cn.zl.springbootredis.service.UserService.UserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

/**
 * @Description:
 * @Author: zhanglang
 * @Date: 2020/9/7 14:56
 */
//启动Springboot应用
@SpringBootTest(classes = SpringbootRedisApplication.class)
@RunWith(SpringRunner.class)
public class TestUserService {
    @Autowired
    private UserService userService;

    @Test
    public void testFindAll(){//测试缓存
        userService.findAll().forEach(user -> System.out.println("user =" + user));
        System.out.println("====================================================");
        userService.findAll().forEach(user -> System.out.println("user =" + user));//第二次会从mybatis的二级缓存获取
    }

    @Test
    public void testFindById(){
        User byId = userService.findById(55L);
        System.out.println("====================================================");
        User byId1 = userService.findById(55L);
    }

    @Test
    public void testDelete(){
        userService.delete(2L);
        System.out.println("====================================================");
    }

    @Test
    public void testSave(){
        User user = new User();
        user.setId(2L).setName("Hali").setAge(21).setPassword("333").setEmail("wwww@163.com");
        userService.save(user);
        System.out.println("====================================================");
    }

    @Test
    public void testUpdate(){
        User user = new User();
        user.setId(1L).setName("Honey").setAge(22).setPassword("334").setEmail("nnn@163.com");
        userService.update(user);
        System.out.println("====================================================");
    }
}
